//
//  MessageViewController.m
//  HJZWeiBo
//
//  Created by 蒋晨成 on 16/5/27.
//  Copyright © 2016年 蒋晨成. All rights reserved.
//

#import "MessageViewController.h"
#import "messageListView.h"
#import "ContactViewController.h"
#import "UIImage+Extend.h"

@interface MessageViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *bgView;

@end

@implementation MessageViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self bgViewIsHidden];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title= @"消息";
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithTitle:@"发现群" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonAction:)];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage resizedImageWithName:@"tabbar_message_center"] style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonAction:)];
    self.navigationItem.rightBarButtonItem = rightBarButton;
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight - 64) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 50;
    [self.view addSubview:_tableView];
    
    
    self.bgView = [[UIView alloc] initWithFrame:self.view.bounds];
    self.bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_bgView];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWidth / 2, kWidth /2)];
    imageView.center = CGPointMake(kWidth / 2, kHeight /2);
    imageView.image = [UIImage imageNamed:@"tabbar_message_center"];
    [self.bgView addSubview:imageView];
    
    [self bgViewIsHidden];
}

- (void)leftBarButtonAction:(UIBarButtonItem *)barButton {
    NSLog(@"发现群");
}

- (void)rightButtonAction:(UIBarButtonItem *)barButton {
    NSLog(@"聊天列表");
    messageListView *messageView = [[messageListView alloc] initWithFrame:CGRectMake(kWidth / 2, 0, kWidth / 2 - 10, 100)];
    messageView.backgroundColor = [UIColor clearColor];
    
    [self.view addSubview:messageView];
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cell_id = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_id];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cell_id];
    }
    NSArray *titleArray = @[@"@我的", @"评论", @"赞"];
    NSArray *imageArray = @[@"at.png", @"comment.png", @"finger.png"];
    cell.textLabel.text = titleArray[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:imageArray[indexPath.row]];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ContactViewController *vc = [[ContactViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)bgViewIsHidden {
    NSString *accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"accessToken"];
    if (!accessToken) {
        self.bgView.hidden = NO;
        return;
    }else {
        self.bgView.hidden = YES;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
